#!/usr/bin/perl

package TTest;
use strict;

use XML::Simple;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Request::Common;
use Data::Dumper;

my $browser = new LWP::UserAgent;
my $xml = new XML::Simple;

sub new {
	my ($type) = @_;
	my $self = {
		page=>'',
		previousPage=>'',
		};
	bless($self,$type);
	return $self;
}

sub loadPage {
	my ($self,$page) = @_;
	$self->{previousPage} = $self->{page};
	my $request = GET "$page/.xml";
	my $page = $browser->request($request);
	if ( $page->is_success ) {
		my $data = $xml->XMLin($self->trim($page->content));
		$self->{page} = $data->{channel};
	} else {
		print("Error when connecting to $page: ".$page->status_line."\n");
	}
}
sub drawPage {
	my($self) = @_;
	print "use strict;\nuse XML::Simple;\nuse LWP::UserAgent;\nuse HTTP::Cookies\nuse HTTP::Request::Common\nuse Data::Dumper;\npackage $self->{page}->{link}\n";
	foreach ( @{$self->{page}->{item}} ) {
		print "$_->{title}\n";
	}
}
sub trim {
	my($self,$string) = @_;
	$string =~ s/^\s+//;
	$string =~ s/\s+$//;
	return $string;
}
